package o;

import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;

public final class xj {
    private static volatile boolean ॱ = true;

    public static Drawable ˎ(Context context, Context context2, @DrawableRes int i) {
        return ॱ(context, context2, i, null);
    }

    public static Drawable ॱ(Context context, @DrawableRes int i, @Nullable Theme theme) {
        return ॱ(context, context, i, theme);
    }

    private static Drawable ॱ(Context context, Context context2, @DrawableRes int i, @Nullable Theme theme) {
        try {
            if (ॱ) {
                return ˎ(context2, i, theme);
            }
        } catch (NoClassDefFoundError e) {
            ॱ = false;
        } catch (IllegalStateException e2) {
            if (!context.getPackageName().equals(context2.getPackageName())) {
                return fo.ˊ(context2, i);
            }
            throw e2;
        } catch (NotFoundException e3) {
        }
        if (theme == null) {
            theme = context2.getTheme();
        }
        return ˋ(context2, i, theme);
    }

    private static Drawable ˎ(Context context, @DrawableRes int i, @Nullable Theme theme) {
        if (theme != null) {
            context = new ax(context, theme);
        }
        return ar.ˋ(context, i);
    }

    private static Drawable ˋ(Context context, @DrawableRes int i, @Nullable Theme theme) {
        return fv.ॱ(context.getResources(), i, theme);
    }
}
